#ifndef UDPSERVER_H_
#define UDPSERVER_H_

#include <vector>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <net/ethernet.h>

#include "ClientHandler.h"

using std::string;
using std::map;

class UDPServer {
private:
	static UDPServer* instance;
	ClientHandler clientHandler;
	map<string, in_addr> clients;
	pthread_t request_thread;
	pthread_t response_thread;
	int raw_socket_fd;
	const int port;
	const int buff_size;
	bool running;

	UDPServer();
	static void* requestThreadRouter(void* cmh);
	static void* responseThreadRouter(void* _this);
	void proccessRequest();
	void proccessResponse();
	string macAddressString(unsigned char* mac);

public:
	static UDPServer* getInstance();

	void run();
	void shutdown(int signal_code = 0);
};

#endif /* UDPSERVER_H_ */
